package homework;

public class Gift implements Runnable {
    private  int gifts = 100;

    @Override
    public void run() {
        while (true) {
            if (gifts < 10) {
                break;
            } else {
                try {
                    Thread.sleep(30);
                    String name = Thread.currentThread().getName();
                    if (name.equals("a")) {
                        System.out.println("a送了第" + (100 - gifts + 1) + "份礼物，还剩" + --gifts + "份礼物");
                    } else if (name.equals("b")) {
                        System.out.println("b送了第" + (100 - gifts + 1) + "份礼物，还剩" + --gifts + "份礼物");
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}